package com.tanhua.admin.api;

import com.tanhua.admin.inter.SummaryApi;
import com.tanhua.admin.mapper.AnalysisMapper;
import com.tanhua.commons.utils.DateUtils;
import com.tanhua.model.vo.LastYear;
import com.tanhua.model.vo.ThisYear;
import com.tanhua.model.vo.UserComparable;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;
@Component
public class SummaryApiImpl implements SummaryApi {
    @Autowired
    private AnalysisMapper analysisMapper;
    @Override
    public UserComparable numRegister(String sd, String ed) {
         String tbDateSd = DateUtils.getTbDate(sd);
        String tbDateEd = DateUtils.getTbDate(ed);
        List<ThisYear> registerList = analysisMapper.queryRegisterThis(sd, ed);
        List<LastYear> registeredList = analysisMapper.queryRegisterLast(tbDateSd, tbDateEd);
        return new UserComparable(registerList, registeredList);


    }

    @Override
    public UserComparable numActive(String sd, String ed) {
        String tbDateSd = DateUtils.getTbDate(sd);
        String tbDateEd = DateUtils.getTbDate(ed);
        List<ThisYear> activeList = analysisMapper.queryActiveThis(sd, ed);
        List<LastYear> activedList = analysisMapper.queryActiveLast(tbDateSd, tbDateEd);
        return new UserComparable(activeList, activedList);

    }

    @Override
    public UserComparable numRetention1d(String sd, String ed) {
        String tbDateSd = DateUtils.getTbDate(sd);
        String tbDateEd = DateUtils.getTbDate(ed);
        List<ThisYear> retention1dList = analysisMapper.queryRetention1dThis(sd, ed);
        List<LastYear> retention1dedList = analysisMapper.queryRetention1dLast(tbDateSd, tbDateEd);
        return new UserComparable(retention1dList,retention1dedList);

    }
}
